# Maintainer: Fabian Bornschein <fabiscafe-at-mailbox-dot-org>
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Geoffroy Carrier <geoffroy.carrier@aur.archlinux.org>
# Contributor: Eric Belanger <belanger@astro.umontreal.ca>
# Contributor: aeolist <aeolist@hotmail.com>
# Contributor: Gabriel Rauter <rauter.gabriel@gmail.com>

pkgbase=sysprof
pkgname=(
  sysprof
  libsysprof-capture
)
pkgver=45.1
pkgrel=1
pkgdesc="Kernel based performance profiler"
url="https://wiki.gnome.org/Apps/Sysprof"
license=(GPL)
arch=(loong64 x86_64)
depends=(
  cairo
  glib2
  graphene
  gtk4
  hicolor-icon-theme
  json-glib
  libadwaita
  libdex
  libpanel
  libunwind
  pango
  polkit
)
makedepends=(
  git
  meson
  yelp-tools
)
_commit=d62c94d62a29be82c187e45e2e17181a4e0c4211  # tags/45.1^0
source=(
  "git+https://gitlab.gnome.org/GNOME/sysprof.git#commit=$_commit"
)
b2sums=('SKIP')

pkgver() {
  cd sysprof
  git describe --tags | sed 's/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd sysprof
}

build() {
  # Ensure static library is non-LTO compatible
  CFLAGS+=" -ffat-lto-objects"

  arch-meson sysprof build
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_sysprof() {
  depends+=(libsysprof-capture)
  groups=(gnome-extra)

  meson install -C build --destdir "$pkgdir"

  cd "$pkgdir"

  _pick capture usr/lib/libsysprof-capture-*
  _pick capture usr/lib/pkgconfig/sysprof-capture-*
  _pick capture usr/include/sysprof-*/sysprof-{address,capture,clock,collector,macros}.h
  _pick capture usr/include/sysprof-*/sysprof-{platform,version,version-macros}.h
  _pick capture usr/include/sysprof-*/sysprof-capture-{condition,cursor,reader,types,writer}.h
}

package_libsysprof-capture() {
  pkgdesc+=" - capture library"
  depends=()
  license=(BSD)

  mv capture/* "$pkgdir"

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 \
    sysprof/src/libsysprof-capture/COPYING
}

# vim:set sw=2 sts=-1 et:
